load(
    "//bazel:skia_rules.bzl",
    "exports_files_legacy",
    "skia_cc_library",
    "skia_cc_test",
    "skia_filegroup",
    "supports_platforms",
)
load("//tools/testrunners/benchmark:android_benchmark_test.bzl", "android_benchmark_test")

licenses(["notice"])

exports_files_legacy()

skia_filegroup(
    name = "gpu_tools",
    srcs = ["GpuTools.h"],
    visibility = ["//tools/viewer:__pkg__"],
)

skia_cc_library(
    name = "benchmark",
    srcs = ["Benchmark.cpp"],
    hdrs = ["Benchmark.h"],
    visibility = ["//tools/testrunners/benchmark:__subpackages__"],
    deps = [
        "//:core",
        "//tools:registry",
    ],
)

COMMON_DEPS = [
    "//:core",
    "//:png_encode_codec",
    "//bench:benchmark",
    "//src/base",
    "//src/core:core_priv",
    "//tools:autorelease_pool",
    "//tools:registry",
    "//tools:resources",
    "//tools:stats",
    "//tools:tool_utils",
    "//tools/flags:cmd_flags",
    "//tools/fonts:font_tool_utils",
    "//tools/testrunners/common:testrunner",
    "//tools/testrunners/common/compilation_mode_keys",
    "//tools/timer",
]

skia_cc_test(
    name = "cpu_nonrendering_test",
    srcs = [
        "GradientBench.cpp",
        "TextBlobBench.cpp",
        "//tools/testrunners/benchmark:BazelBenchmarkTestRunner.cpp",
    ],
    args = [
        "--surfaceConfig",
        "nonrendering",
        "--autoTuneLoops",
    ],
    target_compatible_with = supports_platforms(
        "@platforms//os:linux",
        "@platforms//os:windows",
        "@platforms//os:macos",
    ),
    deps = COMMON_DEPS + [
        "//tools/testrunners/benchmark/target:raster",
    ],
)

skia_cc_test(
    name = "cpu_8888_test",
    srcs = [
        "GradientBench.cpp",
        "TextBlobBench.cpp",
        "//tools/testrunners/benchmark:BazelBenchmarkTestRunner.cpp",
    ],
    args = [
        "--surfaceConfig",
        "8888",
        "--autoTuneLoops",
    ],
    target_compatible_with = supports_platforms(
        "@platforms//os:linux",
        "@platforms//os:windows",
        "@platforms//os:macos",
    ),
    deps = COMMON_DEPS + [
        "//tools/testrunners/benchmark/target:raster",
    ],
)

# Vulkan benchmarks.
[
    skia_cc_test(
        name = name,
        srcs = [
            "GradientBench.cpp",
            "TextBlobBench.cpp",
            "//tools/testrunners/benchmark:BazelBenchmarkTestRunner.cpp",
        ],
        args = [
            "--surfaceConfig",
            surfaceConfig,
            "--autoTuneLoops",
        ],
        target_compatible_with = supports_platforms(
            "@platforms//os:linux",
            "@platforms//os:windows",
            "@platforms//os:macos",
        ),
        deps = COMMON_DEPS + [
            "//tools/testrunners/benchmark/target:ganesh_vulkan",
        ],
    )
    for name, surfaceConfig in [
        [
            "ganesh_vk_test",
            "vk",
        ],
        [
            "ganesh_vk_1010102_test",
            "vk_1010102",
        ],
        [
            "ganesh_vk_msaa4_test",
            "vk_msaa4",
        ],
        [
            "ganesh_vk_msaa8_test",
            "vk_msaa8",
        ],
        [
            "ganesh_vk_dmsaa_test",
            "vk_dmsaa",
        ],
        [
            "ganesh_vk_betex_test",
            "vk_betex",
        ],
        [
            "ganesh_vk_bert_test",
            "vk_bert",
        ],
    ]
]

skia_cc_test(
    name = "ganesh_gles_test",
    srcs = [
        "GradientBench.cpp",
        "TextBlobBench.cpp",
        "//tools/testrunners/benchmark:BazelBenchmarkTestRunner.cpp",
    ],
    args = [
        "--surfaceConfig",
        "gles",
        "--autoTuneLoops",
    ],
    target_compatible_with = supports_platforms(
        "@platforms//os:linux",
        "@platforms//os:windows",
        "@platforms//os:macos",
    ),
    deps = COMMON_DEPS + [
        "//tools/testrunners/benchmark/target:ganesh_gl",
    ],
)

android_benchmark_test(
    name = "cpu_nonrendering_android_test",
    srcs = [
        "GradientBench.cpp",
        "TextBlobBench.cpp",
        "//tools/testrunners/benchmark:BazelBenchmarkTestRunner.cpp",
    ],
    args = [
        "--surfaceConfig",
        "nonrendering",
        "--autoTuneLoops",
    ],
    deps = COMMON_DEPS + [
        "//tools/testrunners/benchmark/target:raster",
    ],
)

android_benchmark_test(
    name = "cpu_8888_android_test",
    srcs = [
        "GradientBench.cpp",
        "TextBlobBench.cpp",
        "//tools/testrunners/benchmark:BazelBenchmarkTestRunner.cpp",
    ],
    args = [
        "--surfaceConfig",
        "8888",
        "--autoTuneLoops",
    ],
    deps = COMMON_DEPS + [
        "//tools/testrunners/benchmark/target:raster",
    ],
)

android_benchmark_test(
    name = "ganesh_gles_android_test",
    srcs = [
        "GradientBench.cpp",
        "TextBlobBench.cpp",
        "//tools/testrunners/benchmark:BazelBenchmarkTestRunner.cpp",
    ],
    args = [
        "--surfaceConfig",
        "gles",
        "--autoTuneLoops",
    ],
    deps = COMMON_DEPS + [
        "//tools/testrunners/benchmark/target:ganesh_gl",
    ],
)

android_benchmark_test(
    name = "ganesh_vk_android_test",
    srcs = [
        "GradientBench.cpp",
        "TextBlobBench.cpp",
        "//tools/testrunners/benchmark:BazelBenchmarkTestRunner.cpp",
    ],
    args = [
        "--surfaceConfig",
        "vk",
        "--autoTuneLoops",
    ],
    deps = COMMON_DEPS + [
        "//tools/testrunners/benchmark/target:ganesh_vulkan",
    ],
)
